package org.example.dao;

import org.apache.ibatis.annotations.*;
import org.example.entity.User;

import java.util.List;


@Mapper
public interface UserDao {
    @Select("select * from `user` where `userName` = #{userName}")
    User findByName(@Param("userName") String userName);

    @Insert("INSERT INTO user (userName,`password`,role) VALUES(#{userName},#{password},#{role})")
    int addUser(User user);

    @Select("select * from user where `id` = #{id}")
    User findById(@Param("id")Integer id);

    //编辑用户信信
    // @Update("UPDATE user SET userName=#{userName}, gender=#{gender}, age=#{age}, phone=#{phone},avatar= #{avatar} WHERE id=#{id}")
    @Update("UPDATE user SET userName=#{userName,jdbcType=VARCHAR}, gender=#{gender,jdbcType=TINYINT}, age=#{age,jdbcType=INTEGER}, phone=#{phone,jdbcType=VARCHAR}, avatar=#{avatar,jdbcType=VARCHAR} WHERE id=#{id,jdbcType=INTEGER}")
    void updateByPrimaryKeySelective(User user);

    //插入数据
    @Insert("INSERT INTO user (userName,gender,age,phone,avatar) VALUES(#{userName},#{gender},#{age},#{phone},#{avatar})")
    int insertSelective(User user);

    //通过id删除用户数据
    @Delete("DELETE FROM user WHERE id = #{id}")
    void deleteByPrimaryKey(Integer id);

    //根据查询条件查询
    List<User> findBySearch(@Param("search")User search);

}
